﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MediPlatform.Domain.Order
{
    /// <summary>
    /// 处方流转订单主表
    /// </summary>
    public class PrescriptionOrder
    {
        /// <summary>
        /// 主键，自增
        /// </summary>
        [Key]
        public long? Id { get; set; }

        /// <summary>
        /// 唯一处方流转订单编号
        /// </summary>
        [StringLength(64)]
        public string? OrderNo { get; set; }

        /// <summary>
        /// 外键，关联 Prescription.Id
        /// </summary>
        public long? PrescriptionId { get; set; }

        /// <summary>
        /// 患者用户ID
        /// </summary>
        public long? PatientId { get; set; }

        /// <summary>
        /// 开具处方的医生ID
        /// </summary>
        public long? DoctorId { get; set; }

        /// <summary>
        /// 导航属性：处方信息
        /// </summary>
        public virtual Prescription? Prescription { get; set; }

        /// <summary>
        /// 导航属性：患者信息
        /// </summary>
        public virtual User? Patient { get; set; }

        /// <summary>
        /// 导航属性：医生信息
        /// </summary>
        public virtual User? Doctor { get; set; }

        /// <summary>
        /// 接收处方的药店ID
        /// </summary>
        public long? PharmacyId { get; set; }

        /// <summary>
        /// 订单状态：0-待发送, 1-已发送, 2-药店已接收, 3-药店已审核, 4-已配药, 5-已取药, 6-已送达, 7-已取消
        /// </summary>
        public int? Status { get; set; }

        /// <summary>
        /// 支付状态：0-待支付, 1-已支付, 2-已退款
        /// </summary>
        public int? PaymentStatus { get; set; }

        /// <summary>
        /// 实际支付金额
        /// </summary>
        [Range(0, double.MaxValue)]
        public decimal? PaymentAmount { get; set; }

        /// <summary>
        /// 优惠金额
        /// </summary>
        public decimal? DiscountAmount { get; set; }

        /// <summary>
        /// 支付方式：wechat, alipay, bank_card
        /// </summary>
        [StringLength(20)]
        public string? PaymentMethod { get; set; }

        /// <summary>
        /// 支付完成时间
        /// </summary>
        public DateTime? PaymentTime { get; set; }

        /// <summary>
        /// 退款金额
        /// </summary>
        public decimal? RefundAmount { get; set; }

        /// <summary>
        /// 退款完成时间
        /// </summary>
        public DateTime? RefundTime { get; set; }

        /// <summary>
        /// 配送地址（JSON格式存储详细信息）
        /// </summary>
        public string? DeliveryAddress { get; set; }

        /// <summary>
        /// 配送物流公司名称
        /// </summary>
        [StringLength(50)]
        public string? LogisticsCompany { get; set; }

        /// <summary>
        /// 物流单号
        /// </summary>
        [StringLength(50)]
        public string? TrackingNumber { get; set; }

        /// <summary>
        /// 签收时间
        /// </summary>
        public DateTime? SignTime { get; set; }

        /// <summary>
        /// 取消原因
        /// </summary>
        public string? CancelReason { get; set; }

        /// <summary>
        /// 扩展信息，如医保结算信息
        /// </summary>
        public string? ExtraInfo { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedAt { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? UpdatedAt { get; set; } = DateTime.Now;
    }
}
